import QtQuick 2.0
import "storage.js" as Storage


Image {
    id: root
    width: 1024
    height: 610
    property real minSize:  Math.min(width/1024, height/610)
    anchors.horizontalCenter: parent.horizontalCenter
    anchors.verticalCenter: parent.verticalCenter
    sourceSize.height: 610 * minSize
    sourceSize.width: 1024 * minSize
    source: "../picture/p_home/p_home_null.png"
    fillMode: Image.PreserveAspectFit


    signal qmlSN_sqlWriteFinish()
    onQmlSN_sqlWriteFinish: {

        if($sqlMcRecorder.qml_getBitBool("A套","调节器状态","本通道运行")===true) ph_channal.state = "A"
        else if($sqlMcRecorder.qml_getBitBool("B套","调节器状态","本通道运行")===true) ph_channal.state = "B"
        else ph_channal.state = "N"

        var tWhich = Storage.readWhichChannelRunning()
        if($sqlMcRecorder.qml_getBitBool(tWhich,"调节器状态","并网运行")===true) ph_cut.state = "in"
        else ph_cut.state = "off"

        if($sqlMcRecorder.qml_getBitBool("A套","调节器状态","自动方式")===true) ph_Aaorn.state = "auto"
        else if($sqlMcRecorder.qml_getBitBool("A套","调节器状态","手动方式")===true) ph_Aaorn.state = "manual"
        if($sqlMcRecorder.qml_getBitBool("B套","调节器状态","自动方式")===true) ph_Baorn.state = "auto"
        else if($sqlMcRecorder.qml_getBitBool("B套","调节器状态","手动方式")===true) ph_Baorn.state = "manual"

        if(Math.abs($sqlMcRecorder.qml_getRecordVal_bystr_toint16("A套控制信号")-
                    $sqlMcRecorder.qml_getRecordVal_bystr_toint16("B套控制信号"))>200)
            ph_switchFault.visible = true;
        else
            ph_switchFault.visible = false;

        var t_strCounter=0;

        ph_limiterQuickText.text = ""
        if($sqlMcRecorder.qml_getBitBool("A套","调节器故障","过励限制")===true) {ph_limiterQuickText.text = ph_limiterQuickText.text + "A套过励限制\n"; t_strCounter++}
        if($sqlMcRecorder.qml_getBitBool("A套","调节器故障","欠励限制")===true) {ph_limiterQuickText.text = ph_limiterQuickText.text + "A套欠励限制\n"; t_strCounter++}
        if($sqlMcRecorder.qml_getBitBool("A套","调节器故障","VF限制")===true) {ph_limiterQuickText.text = ph_limiterQuickText.text + "A套VF限制\n"; t_strCounter++}
        if($sqlMcRecorder.qml_getBitBool("A套","调节器故障","强励限制")===true) {if(t_strCounter <3) ph_limiterQuickText.text = ph_limiterQuickText.text + "A套强励限制\n"; t_strCounter++}
        if($sqlMcRecorder.qml_getBitBool("A套","调节器故障","定子电流限制")===true) {if(t_strCounter <3) ph_limiterQuickText.text = ph_limiterQuickText.text + "A套定子电流限制\n"; t_strCounter++}
        if($sqlMcRecorder.qml_getBitBool("A套","调节器故障","过无功限制")===true) {if(t_strCounter <3) ph_limiterQuickText.text = ph_limiterQuickText.text + "A套过无功限制\n"; t_strCounter++}
        if($sqlMcRecorder.qml_getBitBool("A套","调节器故障","最小励磁电流限制")===true) {if(t_strCounter <3) ph_limiterQuickText.text = ph_limiterQuickText.text + "A套最小励磁电流限制\n"; t_strCounter++}

        if($sqlMcRecorder.qml_getBitBool("B套","调节器故障","过励限制")===true) {if(t_strCounter <3) ph_limiterQuickText.text = ph_limiterQuickText.text + "B套过励限制\n"; t_strCounter++}
        if($sqlMcRecorder.qml_getBitBool("B套","调节器故障","欠励限制")===true) {if(t_strCounter <3) ph_limiterQuickText.text = ph_limiterQuickText.text + "B套欠励限制\n"; t_strCounter++}
        if($sqlMcRecorder.qml_getBitBool("B套","调节器故障","VF限制")===true) {if(t_strCounter <3) ph_limiterQuickText.text = ph_limiterQuickText.text + "B套VF限制\n"; t_strCounter++}
        if($sqlMcRecorder.qml_getBitBool("B套","调节器故障","强励限制")===true) {if(t_strCounter <3) ph_limiterQuickText.text = ph_limiterQuickText.text + "B套强励限制\n"; t_strCounter++}
        if($sqlMcRecorder.qml_getBitBool("B套","调节器故障","定子电流限制")===true) {if(t_strCounter <3) ph_limiterQuickText.text = ph_limiterQuickText.text + "B套定子电流限制\n"; t_strCounter++}
        if($sqlMcRecorder.qml_getBitBool("B套","调节器故障","过无功限制")===true) {if(t_strCounter <3) ph_limiterQuickText.text = ph_limiterQuickText.text + "B套过无功限制\n"; t_strCounter++}
        if($sqlMcRecorder.qml_getBitBool("B套","调节器故障","最小励磁电流限制")===true) {if(t_strCounter <3) ph_limiterQuickText.text = ph_limiterQuickText.text + "B套最小励磁电流限制\n"; t_strCounter++}
        if(t_strCounter >3) ph_limiterQuickText.text += "..."
        if(t_strCounter >=1) page1.limiterStatu = true
        else page1.limiterStatu = false
    }

    function qmlSN_sqlAlarmWriteFinish(var_now,var_history)
    {
        if(var_history.length===0) return;
            ph_faultQuickText.text = "";
        var var4;
        if(var_now.length > 5*3) var4 = 5
        else var4 = var_now.length/3;
        for(var i=0; i<var4; i++)
        {
            ph_faultQuickText.text +=  var_now[3*i+2] + "\n"
        }
        if(var_now.length > 5*3) ph_faultQuickText.text +=  "..."

        if(var_now.length!==0) page1.errorStatu = true
        else page1.errorStatu = false
    }

    Text {
        id:text_operator
        x: 790*minSize
        y: 8*minSize
        state: "1"
        color: "#44fdfd"
        font.bold: true
        styleColor: "#c37373"
        font.pixelSize: 33*minSize
        states:[
            State {
                name: "1"
                PropertyChanges {
                    target: text_operator
                    text: qsTr("普通操作员")
                    color: "paleturquoise"
                }
            },
            State {
                name: "50"
                PropertyChanges {
                    target: text_operator
                    text: qsTr("中级操作员")
                    color: "darkolivegreen"
                }
            },
            State {
                name: "90"
                PropertyChanges {
                    target: text_operator
                    text: qsTr("高级操作员")
                    color: "mediumvioletred"
                }
            },
            State {
                name: "95"
                PropertyChanges {
                    target: text_operator
                    text: qsTr("调试人员")
                    color: "hotpink"
                }
            },
            State {
                name: "100"
                PropertyChanges {
                    target: text_operator
                    text: qsTr("开发者 谨慎操作")
                    color: "Red"
                }
            }
        ]
        Timer{
            interval: 500
            repeat: true
            triggeredOnStart: false
            running: true
            property int mdate: 0
            onTriggered: {
                if($sqlMcRecorder.qml_getOperaterMode()===50) text_operator.state= "50"
                else if($sqlMcRecorder.qml_getOperaterMode()===90) text_operator.state= "90"
                else if($sqlMcRecorder.qml_getOperaterMode()===95) text_operator.state= "95"
                else if($sqlMcRecorder.qml_getOperaterMode()===100) text_operator.state= "100"
                else text_operator.state= "1"
            }
        }
        MouseArea{
            anchors.fill: parent
            onClicked: {excSecret.visible=true}
        }
    }

    Timer{
        interval: 100
        repeat: true
        triggeredOnStart: false
        running: true
        property int mdate: 0
        onTriggered: {
            mdate++;
            if(mdate>5) {
                text_time.text = (new Date).toLocaleString(Qt.locale(), "yyyy-MM-dd hh:mm:ss")
                mdate=0
            }
        }
    }

    Text {
        id: text_time
        x: 80*minSize
        y: 40*minSize
//        x: 750*minSize
//        y: 85*minSize
        color: "#44fdfd"
        text: qsTr("00-00")
        font.pixelSize: 28*minSize
        styleColor: "#c37373"
    }

    Text {
        id: text_tips
        x: 820*minSize
        y: 85*minSize
        color: "#44fdfd"
        text: qsTr("全\t屏")
        font.pixelSize: 33*minSize
        styleColor: "#c37373"
        MouseArea{
            anchors.fill: parent
            onClicked: excRecordDisplayer.sl_fullScreen()
        }
    }

    Image {
        id:ph_cut
        x: 123*parent.minSize
        y: 109*parent.minSize
        width: sourceSize.width*parent.minSize
        height: sourceSize.height*parent.minSize
        fillMode: Image.PreserveAspectFit
        source: "../picture/p_home/cutoff.png"
        states: [
            State {
                name: "off"
                PropertyChanges {
                    target: ph_cut
                    source: "../picture/p_home/cutoff.png"
                }
            },
            State {
                name: "in"
                PropertyChanges {
                    target: ph_cut
                    source: "../picture/p_home/cutin.png"
                }
            }
        ]
        MouseArea {
            anchors.fill: parent
            onPressed: parent.scale=0.95
            onReleased: {parent.scale=1;main_svshow.currentIndex=2}
        }
    }
    Image {
        id:ph_channal
        x: 448*minSize
        y: 267*minSize
        width: sourceSize.width*parent.minSize
        height: sourceSize.height*parent.minSize
        fillMode: Image.PreserveAspectFit
        source: "../picture/p_home/A.png"

        states: [
            State {
                name: "A"
                PropertyChanges {
                    target: ph_channal
                    source: "../picture/p_home/A.png"
                }
            },
            State {
                name: "B"
                PropertyChanges {
                    target: ph_channal
                    source: "../picture/p_home/B.png"
                }
            },
            State {
                name: "N"
                PropertyChanges {
                    target: ph_channal
//                                source: "../picture/p_home/cutin.png"
                }
            }
        ]
        MouseArea {
            anchors.fill: parent
            onPressed: parent.scale=0.95
            onReleased: {parent.scale=1;main_svshow.currentIndex=1}
        }
    }
    Image {
        x: 133*parent.minSize
        y: 442*parent.minSize
        width: sourceSize.width*parent.minSize
        height: sourceSize.height*parent.minSize
        fillMode: Image.PreserveAspectFit
        source: "../picture/p_home/fault.png"
        MouseArea {
            anchors.fill: parent
            onPressed: parent.scale=0.95
            onReleased: {parent.scale=1;main_svshow.currentIndex=4}
        }
    }
    Image {
        x: 702*parent.minSize
        y: 178*parent.minSize
        width: sourceSize.width*parent.minSize
        height: sourceSize.height*parent.minSize
        fillMode: Image.PreserveAspectFit
        source: "../picture/p_home/limiter.png"
        MouseArea {
            anchors.fill: parent
            onPressed: parent.scale=0.95
            onReleased: {parent.scale=1;main_svshow.currentIndex=5}
        }
    }
    Image {
        x: 677*parent.minSize
        y: 405*parent.minSize
        width: sourceSize.width*parent.minSize
        height: sourceSize.height*parent.minSize
        fillMode: Image.PreserveAspectFit
        source: "../picture/p_home/runningMode.png"
        MouseArea {
            anchors.fill: parent
            onPressed: parent.scale=0.95
            onReleased: {parent.scale=1;main_svshow.currentIndex=8}
        }
    }
    Image {
        id:ph_switchFault
        x: 402*parent.minSize
        y: 390*parent.minSize
        width: sourceSize.width*parent.minSize
        height: sourceSize.height*parent.minSize
        fillMode: Image.PreserveAspectFit
        visible: false
        source: "../picture/p_home/switchFault.png"
    }
    Image {
        id:ph_Aaorn
        x: 536*parent.minSize
        y: 530*parent.minSize
        width: sourceSize.width*parent.minSize
        height: sourceSize.height*parent.minSize
        fillMode: Image.PreserveAspectFit
        source: "../picture/p_home/manual.png"

        states: [
            State {
                name: "auto"
                PropertyChanges {
                    target: ph_Aaorn
                    source: "../picture/p_home/auto.png"
                }
            },
            State {
                name: "manual"
                PropertyChanges {
                    target: ph_Aaorn
                    source: "../picture/p_home/manual.png"
                }
            }
        ]
    }
    Image {
        id:ph_Baorn
        x: 760*parent.minSize
        y: 530*parent.minSize
        width: sourceSize.width*parent.minSize
        height: sourceSize.height*parent.minSize
        fillMode: Image.PreserveAspectFit
        source: "../picture/p_home/manual.png"
    }
    Text {
        id: ph_faultQuickText
        x: 50
        y: 250
        width: 220
        height: 139
        color: "#40FFFF"
//                    text: qsTr("Text Area")
        font.pointSize: 15
    }
    Text {
        id: ph_limiterQuickText
        x: 400
        y: 100
        width: 220
        height: 100
        color: "#40FFFF"
//                    text: qsTr("Text Area")
        font.pointSize: 15
    }

    EXC_Secret{
        id:excSecret
        anchors.horizontalCenter: parent.horizontalCenter
        anchors.verticalCenter: parent.verticalCenter
        visible: false
    }
}


/*##^##
Designer {
    D{i:0;formeditorZoom:0.6600000262260437}
}
##^##*/
